/*
 * @(#)Xfcpp.java        1.0 2000/05/09
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfcpp;

import xfuzzy.lang.*;
import java.io.*;

/**
 * Herramienta que genera una descripci�n del sistema difuso en C++
 * 
 * @author Francisco Jos� Moreno Velo 
 *
 */
public class Xfcpp {

	//----------------------------------------------------------------------------//
	//                            COSTANTES PRIVADAS                              //
	//----------------------------------------------------------------------------//

	/**
	 * Car�cter de fin de linea dependiente de la plataforma
	 */

	private static String eol = System.getProperty("line.separator", "\n");

	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Mensaje a mostrar al terminar la ejecuci�n
	 */
	private String msg;

	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//

	/**
	 * Constructor
	 */
	public Xfcpp(Specification spec, File dir) {
		File wdir = null;
		if(dir == null) wdir = spec.getFile().getParentFile();
		else wdir = dir;
		this.msg = "";
		try {
			String msgsc = XfcppSpecCppCode.create(spec,wdir);
			String msgsh = XfcppSpecHppCode.create(spec,wdir);
			String msgxh = XfcppXfuzzyHppCode.create(wdir);
			String msgxc = XfcppXfuzzyCppCode.create(wdir);
			msg += "C++ code generation describing the fuzzy system "+spec.getName();
			msg += " has been successfully finished."+eol;
			msg += "C++ description is included in files: "+eol;
			msg += "        \""+msgxh+"\","+eol;
			msg += "        \""+msgxc+"\","+eol;
			msg += "        \""+msgsh+"\","+eol;
			msg += "        and \""+msgsc+"\".";
		} catch(XflException ex) {
			msg += "Fatal error generating a C++ description.";
		}
	}

	//----------------------------------------------------------------------------//
	//                        M�TODOS P�BLICOS EST�TICOS                          //
	//----------------------------------------------------------------------------//

	/**
	 * Ejecuci�n externa
	 */
	public static void main(String args[]) {
		String filename = "";
		if(args.length == 1) filename = args[0];
		else {
			System.out.println("Usage: xfc xflfile");
			System.exit(-1);
		}
		XflParser xflparser = new XflParser();
		Specification spec = xflparser.parse(filename);
		if(spec == null) { System.out.println(xflparser.resume()); System.exit(-1); }
		Xfcpp compiler = new Xfcpp(spec,null);
		System.out.println(compiler.getMessage());
		System.exit(0);
	}

	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * M�todo que describe el resultado
	 */
	public String getMessage() {
		return msg;
	}

}
